export default {
	get(url, data) {
		let token = uni.getStorageSync('token')
		return new Promise((reslove, joke) => {
			uni.request({
				url: url,
				data: data,
				method: "GET",
				dataType: 'json',
				header: {
					'authorization': token
				},
				success: (res) => {
					if (res.data.code == 401) {
						uni.removeStorageSync('token')
						uni.showModal({
							title: '提示',
							content: '登录过期',
							success: (res) => {
								if (res.confirm) {
									uni.redirectTo({
										url: '/pages/all/login/login'
									})
								} else if (res.cancel) {
									console.log('用户取消')
								}
							}
						})
					}
					reslove(res.data)
				},
				fail: (err) => {
					uni.showToast({
						title: '网络请求失败',
						icon: 'none'
					})
				}
			})
		})
	},
	post(url, data) {
		let token = uni.getStorageSync('token')
		return new Promise((reslove, joke) => {
			uni.request({
				url: url,
				data: data,
				method: "POST",
				dataType: 'json',
				header: {
					'content-type':'application/json',
					'authorization': token
				},
				success: (res) => {
					if (res.data.code == 401) {
						uni.removeStorageSync('token')
						uni.showModal({
							title: '提示',
							content: '登录过期',
							success: (res) => {
								if (res.confirm) {
									uni.redirectTo({
										url: '/pages/all/login/login'
									})
								} else if (res.cancel) {
									console.log('用户取消')
								}
							}
						})
					}
					reslove(res.data)
				},
				fail: (err) => {
					console.log(err)
					uni.showToast({
						title: '网络请求失败',
						icon: 'none'
					})
				}
			})
		})
	},
	put(url, data) {
		let token = uni.getStorageSync('token')
		return new Promise((reslove, joke) => {
			uni.request({
				url: url,
				data: data,
				method: "PUT",
				dataType: 'json',
				header: {
					'content-type':'application/json',
					'authorization': token
				},
				success: (res) => {
					if (res.data.code == 401) {
						uni.removeStorageSync('token')
						uni.showModal({
							title: '提示',
							content: '登录过期',
							success: (res) => {
								if (res.confirm) {
									uni.redirectTo({
										url: '/pages/all/login/login'
									})
								} else if (res.cancel) {
									console.log('用户取消')
								}
							}
						})
					}
					reslove(res.data)
				},
				fail: (err) => {
					uni.showToast({
						title: '网络请求失败',
						icon: 'none'
					})
				}
			})
		})
	}
}
